package com.csr;

import android.app.AlertDialog;
import android.app.ProgressDialog;
import android.app.TabActivity;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.pm.FeatureInfo;
import android.content.res.Resources;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.TabHost;
import android.widget.TextView;
import android.widget.TabHost.OnTabChangeListener;
import android.widget.TabHost.TabSpec;

public class ResellerResultTabActivity extends TabActivity  implements OnTabChangeListener
{
	TabHost tabHost;
	TabHost.TabSpec spec;
 	Intent intent; 
 	Resources res;
 	Button btnBack,btnLogout;
 	
 	@Override
    public void onCreate(Bundle savedInstanceState) 
    {
    	super.onCreate(savedInstanceState);  
        requestWindowFeature(Window.FEATURE_NO_TITLE);
		getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
		WindowManager.LayoutParams.FLAG_FULLSCREEN);
		setContentView(R.layout.reseller_result_tabactivity);
		 
		System.out.println("Get Parent Activity Name:");
		if(getIntent().getExtras().getString("calleractivity").equals("favourite"))
		{
			TextView header=(TextView)findViewById(R.id.tv_headerText);
			header.setText("Favourite");
		}
		
		btnBack=(Button)findViewById(R.id.btnPrevious);
	    btnLogout=(Button)findViewById(R.id.btnLogout);
		res = getResources();
        
        tabHost = getTabHost();
        intent = new Intent().setClass(this,ResellerResult.class).putExtra("istabactivity", true).addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
        setupTab("Info", intent);
        
//        spec = tabHost.newTabSpec("Info").setIndicator("Info")
//                .setContent(intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP));
//        tabHost.addTab(spec);
         
        intent = new Intent().setClass(this,AddBalanceActivity.class).putExtra("istabactivity", true).addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
        setupTab("Add Balance", intent);
        
        
        //       spec = tabHost.newTabSpec("Balance").setIndicator("Add Bal ")
//               .setContent(intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP));
//        tabHost.addTab(spec);
        
        intent = new Intent().setClass(this,WeeklyStatementActivity.class).putExtra("istabactivity", true).addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
        setupTab("Statement", intent);
//        spec = tabHost.newTabSpec("Statement").setIndicator("Statement")
//               .setContent(intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP));
//        
//        tabHost.addTab(spec);
        
        
    /*  tabHost.getTabWidget().getChildAt(0).setBackgroundResource(R.drawable.information_hover);
        tabHost.getTabWidget().getChildAt(1).setBackgroundResource(R.drawable.add_balanace);
        tabHost.getTabWidget().getChildAt(2).setBackgroundResource(R.drawable.weekly_statement);
        tabHost.setOnTabChangedListener(this);*/
        
        
        btnBack.setOnClickListener(new OnClickListener()
		{
			public void onClick(View arg0) 
			{
	 			finish();
			}
		});
        
		btnLogout.setOnClickListener(new OnClickListener()
		{ 
			public void onClick(View v) 
			{
				new AlertDialog.Builder(ResellerResultTabActivity.this)
		        .setTitle( "Exit Application" )
		        .setMessage( "Are you sure you want to Logout?" )
		        .setPositiveButton("YES", new android.content.DialogInterface.OnClickListener() 
		        {
		            public void onClick(DialogInterface arg0, int arg1) 
		            {
		            	setResult(3);
		            	finish();
		            }
  
		        })
		        .setNegativeButton("NO",  new android.content.DialogInterface.OnClickListener() 
		        {
		            public void onClick(DialogInterface arg0, int arg1)
		            {
		                //do stuff onclick of CANCEL
		            	arg0.dismiss();
		            }

					public void onClick(View v) 
					{
						// TODO Auto-generated method stub
					}
		        }).show(); 
			}
		});
    }

 	private void setupTab(final String tag,Intent intent)
    {
    	View tabview = createTabView(tabHost.getContext(), tag);
    	
        TabSpec setContent = tabHost.newTabSpec(tag).setIndicator(tabview).setContent(intent);
        tabHost.addTab(setContent);
    }
    
    private static View createTabView(final Context context, final String text) 
    {
    	View view = LayoutInflater.from(context).inflate(R.layout.tabs_bg, null);
    	TextView tv = (TextView) view.findViewById(R.id.tabsText);
    	tv.setText(text);
    	return view;
    }
	public void onTabChanged(String tabName)
	{
		if(tabName.equalsIgnoreCase("Info"))
		{
			tabHost.getTabWidget().getChildAt(tabHost.getCurrentTab()).setBackgroundResource(R.drawable.information_hover);
			tabHost.getTabWidget().getChildAt(1).setBackgroundResource(R.drawable.add_balanace);
		    tabHost.getTabWidget().getChildAt(2).setBackgroundResource(R.drawable.weekly_statement);
		}
		else if(tabName.equalsIgnoreCase("Balance"))
		{
			tabHost.getTabWidget().getChildAt(tabHost.getCurrentTab()).setBackgroundResource(R.drawable.add_balance_hover);
			tabHost.getTabWidget().getChildAt(0).setBackgroundResource(R.drawable.information);
		    tabHost.getTabWidget().getChildAt(2).setBackgroundResource(R.drawable.weekly_statement);
		}
		else if(tabName.equalsIgnoreCase("Statement"))
		{
			tabHost.getTabWidget().getChildAt(tabHost.getCurrentTab()).setBackgroundResource(R.drawable.weekly_statement_hover);
			tabHost.getTabWidget().getChildAt(0).setBackgroundResource(R.drawable.information);
		    tabHost.getTabWidget().getChildAt(1).setBackgroundResource(R.drawable.add_balanace);
		     
		}
		
	}
}
